#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    player = new QMediaPlayer(this);
    QMediaContent media(QUrl("../../music/aiqingniao.mp3"));
    player->setMedia(media);

    playList = new QMediaPlaylist(this);
    connect(playList, SIGNAL(currentIndexChanged(int)), player, SLOT(play()));
    playList->addMedia(QMediaContent(QUrl("../../music/aiqingniao.mp3")));
    playList->addMedia(QMediaContent(QUrl("../../music/xiaolian.mp3")));
    playList->addMedia(QMediaContent(QUrl("../../music/suiyuan.mp3")));
    playList->addMedia(QMediaContent(QUrl("http://m7.music.126.net/20191010132340/3bb1b1b739fb6adea8c24d467dff097f/ymusic/5aaf/f934/0f63/f7ec7bf8f60da795443a11df90dffee3.mp3")));
    playList->addMedia(QMediaContent(QUrl("http://m7.music.126.net/20191010133032/d1671d09639d05202e1c8d38d157fb5a/ymusic/eb6b/52a9/e1c7/f219c9411c82e07be085d1cf344978d8.mp3")));
    playList->addMedia(QMediaContent(QUrl("http://m8.music.126.net/20191010133335/abd90c7bba775c73298e3f1f2c720489/ymusic/9c05/4f5b/32d4/cc23429beb825d752bda53fcb39ef9c3.mp3")));

    player->setPlaylist(playList);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    player->play();
}

void MainWindow::on_pushButton_2_clicked()
{
    player->pause();
}

void MainWindow::on_pushButton_3_clicked()
{
    player->stop();
}

void MainWindow::on_pushButton_4_clicked()
{
    playList->previous();
}

void MainWindow::on_pushButton_5_clicked()
{
    playList->next();
}
